/********************************************************/
/*	GameLoopHandler class DLLEXPORT by George Chew				*/
/*	For use in GeorgeLib								*/
/*	Created Mar 2013									*/
/*														*/
/*	Version 0001										*/
/********************************************************/

#ifndef __GAME_LOOP_HANDLER_H__
#define __GAME_LOOP_HANDLER_H__

#include "stdafx.h"
#include "Logger.h"
#include "Timer.h"

#define GameLoopHandler GeorgeLib::_GameLoopHandler::getInstance()

namespace GeorgeLib
{

class DLLEXPORT _GameLoopHandler
{

	/*		How to use this class DLLEXPORT DLLEXPORT		*/
	// if(GameLoopHandler->LimitRendering()) DoRender();
	// LimitRendering(DoRender);

private:
	static	_GameLoopHandler*	GameLoopHandler_Instance;	// Singleton Instance
	static	float				framerate;					// Rate of render, defaulted at 48
	static	float				updaterate;					// Rate of update, defaulted at 60
	static	double				FPSprevTime;				// Frame rate limit timekeeper
	static	double				RTLprevTime;				// Update rate limit timekeeper
	
public:
	_GameLoopHandler(void);		// Constructor
	~_GameLoopHandler(void);		// Destructor

	// Get the singleton instance of this class DLLEXPORT DLLEXPORT
	static	_GameLoopHandler*	getInstance		(void);

	// Accessors
			float				getFramerate	(void);
			float				getUpdaterate	(void);

	// Mutators
			void				setFramerate	(float framerate);
			void				setUpdaterate	(float updaterate);

	// Starts a timer, returns true when it has reached (1000 / framerate)ms
			bool				LimitRendering	(void);

	// Starts a timer, returns true when it has reached (1000 / updaterate)ms
			bool				LimitUpdating	(void);

	// Starts a timer, calls the function paased in when it has reached (1000 / framerate)ms
			void				LimitRendering	(void (*callback)(void));

	// Starts a timer, calls the function paased in when it has reached (1000 / updaterate)ms
			void				LimitUpdating	(void (*callback)(void));
};

} // namespace GeorgeLib

#endif // __GAME_LOOP_HANDLER_H__ //